<template>
    <div>
        <el-form-item label="问题总分">
            <el-input-number v-model="self0ptions.options.totalSource" :min="0" :max="100" :precision="2"
                             @change="changValue"></el-input-number>
        </el-form-item>
    </div>
</template>

<script>
import {formGlobalConf, containerConfigList} from '@/components/form-designer/container-panel/containerConfig'
export default {
    name: "totalSource-editor",
    props: {
        self0ptions: {
            type: Object,
        },
        prentData: {
            type: Object,
        }
    },
    data() {
        return {
            memoryNum: 0,
        }
    },
    created() {
        this.memoryNum = this.self0ptions.options.totalSource
    },
    methods: {
        changValue() {
            let num = 0;
            for (let val of containerConfigList) {
                if (this.prentData.id == val.id) continue
                for (let childVal of val.widgetList) {
                    num = num + childVal.options.totalSource
                }
            }
            const ind = containerConfigList.findIndex(item => item.id == this.prentData.id)
            if (ind != -1) {
                for (let val of containerConfigList[ind].widgetList) {
                    if (this.self0ptions.id == val.id) continue
                    num = num + val.options.totalSource
                }
            }
            num = num + this.self0ptions.options.totalSource
            if (formGlobalConf.totalSource < num) {
                //如果超出了就还是设为之前的权重比对
                this.self0ptions.options.totalSource = this.memoryNum
                this.$message.error('分数设置超出了当前全局分数设置')
            }

        }
    }
}
</script>

<style scoped>

</style>